package com.clk.clksense;

import java.util.ArrayList;

import com.clk.clksense.network.TCPClient;

import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;

public class Security extends Activity {

	public final static int SUCCESS_RETURN_CODE = 1;
	private TCPClient mTcpClient;
    private ArrayList<String> arrayList;

	// ----------------------------------------------------------------------------------
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_security);
		new connectTask().execute("");
		mTcpClient.sendMessage("ilk mesaj");
	}

	// ----------------------------------------------------------------------------------
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_security, menu);
		return true;
	}

	// ----------------------------------------------------------------------------------
	public void logoutClick(View view) {
		Intent intent = new Intent();
		Bundle b = new Bundle();
		b.putString("TEXT", "cikildi");
		intent.putExtras(b);
		setResult(SUCCESS_RETURN_CODE, intent);
		finish();
	}
	// ----------------------------------------------------------------------------------
	// ----------------------------------------------------------------------------------
	class connectTask extends AsyncTask<String, String, TCPClient> {

		@Override
		protected TCPClient doInBackground(String... message) {

			// we create a TCPClient object and
			mTcpClient = new TCPClient(new TCPClient.OnMessageReceived() {
				@Override
				// here the messageReceived method is implemented
				public void messageReceived(String message) {
					// this method calls the onProgressUpdate
					publishProgress(message);
				}
			});
			mTcpClient.run();

			return null;
		}

		@Override
		protected void onProgressUpdate(String... values) {
			super.onProgressUpdate(values);

			// in the arrayList we add the messaged received from server
			arrayList.add(values[0]);
			// notify the adapter that the data set has changed. This means that
			// new message received
			// from server was added to the list
			//mAdapter.notifyDataSetChanged();
		}
	}
	// ----------------------------------------------------------------------------------
}
